package ccot.util;

public class ConvertFormat {
	
	public static void run(String inFilename, String outFilename) {
		StringBuilder sb = new StringBuilder();
		String[] rows = Tools.read(inFilename, "GBK").split("\n");
		for (String row : rows) {
			String[] cols = row.split("\t");
			if (cols[0].equals("bh")) {
				continue;
			}
			sb.append(cols[0] + "\t" + cols[1] + "\t" + cols[2] + "\t" + cols[3] + "\t");
			
			String code = cols[4];
			String choice = "";
			for (int i = 0; i < 4; i++) {
				if (code.charAt(i) == '1') {
					choice += (char)('a' + i);
				}
			}
			if (cols[1].equals("1")) {
				if (choice.equals("a")) {
					choice = "t";
				} else if (choice.equals("b")) {
					choice = "f";
				}
			}
			sb.append(choice);
			for (int i = 5; i < cols.length; i++) {
				sb.append("\t" + cols[i]);
			}
			sb.append("\n");
			
			System.out.println("code=" + code + ", choice=" + choice);
			Tools.write(outFilename, sb.toString(), "GBK");
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		String inFilename = args[0];
		String outFilename = args[1];
		
		ConvertFormat.run(inFilename, outFilename);

	}

}
